package config.Strategy;

import com.baomidou.mybatisplus.generator.config.builder.Mapper;
import config.Config;
import org.apache.commons.lang3.StringUtils;

/**
 * @Description config.Strategy
 * @Author zhengzetao
 * @Date 2022/9/18 18:34
 */
public class MapperConfig extends Config {

    final private static String GROUP = "StrategyConfig.Mapper";

    //superClass(String)	设置父类	com.baomidou.global.BaseMapper
    private String superClass;
    //enableMapperAnnotation	开启 @Mapper 注解	默认值:false
    private Boolean enableMapperAnnotation;
    //enableBaseResultMap	启用 BaseResultMap 生成	默认值:false
    private Boolean enableBaseResultMap;
    //enableBaseColumnList	启用 BaseColumnList	默认值:false
    private Boolean enableBaseColumnList;
    //formatMapperFileName(String)	格式化 mapper 文件名称 %sDao
    private String formatMapperFileName;
    //formatXmlFileName(String)	格式化 xml 实现类文件名称 %sXml
    private String formatXmlFileName;

    private MapperConfig() {
        super(GROUP);
        this.superClass = getStr("superClass");
        this.formatXmlFileName = getStr("formatXmlFileName");
        this.formatMapperFileName = getStr("formatMapperFileName");
        this.enableBaseResultMap = getBoolDefaultFalse("enableBaseResultMap");
        this.enableBaseColumnList = getBoolDefaultFalse("enableBaseColumnList");
        this.enableMapperAnnotation = getBoolDefaultFalse("enableMapperAnnotation");
    }

    public static void setting(Mapper.Builder builder) {
        MapperConfig config = new MapperConfig();
        if (StringUtils.isNotBlank(config.superClass)) {
            builder.superClass(config.superClass);
        }
        if (StringUtils.isNotBlank(config.formatMapperFileName)) {
            builder.formatMapperFileName(config.formatMapperFileName);
        }
        if (StringUtils.isNotBlank(config.formatXmlFileName)) {
            builder.formatXmlFileName(config.formatXmlFileName);
        }
        if (config.enableBaseResultMap) {
            builder.enableBaseResultMap();
        }
        if (config.enableBaseColumnList) {
            builder.enableBaseColumnList();
        }
        if (config.enableMapperAnnotation) {
            builder.enableMapperAnnotation();
        }
    }
}
